<template>
  <div>
    <div>
      <van-nav-bar
      fixed=true 
      placeholder=true
        title="AddressEdit"
        left-text=""
        left-arrow
        @click-left="onClickFanHui"
      >
      </van-nav-bar>
    </div>

    <div>
      <van-address-edit
        :area-list="areaList"
        :address-info="this.addressinfo"
        show-postal
        show-delete
        show-set-default
        show-search-result
        :search-result="searchResult"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="onDelete"
        @change-detail="onChangeDetail"
      />
    </div>
  </div>
</template>
<script>
import { Toast } from "vant";
import { areaList } from "@vant/area-data";
export default {
  data() {
    return {
      areaList,
      searchResult: [],
      addressinfo: 90,
    };
  },
  created() {
    
    this.addressinfo = {
      id: this.$store.state.addressId,
      name: this.$store.state.addressName,
      tel: this.$store.state.addressTel,
    };
  },
  methods: {
    onClickFanHui() {
        this.$router.go(-1)

    },
    onSave(content) {
      console.log(content);
      let config = {
        headers: { "Content-Type": "application/json" },
      };
      this.axios.post("/aapi/tianjiadizhi", content, config).then((res) => {
        if(res.status===201){
          Toast("添加成功");
        }else{
          Toast("修改成功")
        }
        this.$router.push("/addresslist");
      });
    },
    onDelete() {
      Toast("delete");
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
};
</script>
